package in.unlocker.apps.unlock.service;

import in.unlocker.apps.unlock.dao.UserRepository;
import in.unlocker.apps.unlock.model.Profile;
import in.unlocker.apps.unlock.model.registration.User;
import in.unlocker.apps.unlock.service.exception.ApplicationException;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.PostConstruct;
import javax.persistence.PersistenceException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service("userService")
public class UserService extends AbstractService implements UserDetailsService
{

	Log log = LogFactory.getLog(UserService.class);
	@Autowired
	private UserRepository userRepository;

	private static final String DUMMY_PASSWORD = "password";

	@PostConstruct
	protected void initialize()
	{
		// userRepository.save(new User("user", "demo", "ROLE_USER"));
		// userRepository.save(new User("admin", "admin", "ROLE_ADMIN"));
	}

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException
	{
		return null;
	}

	private void updateProfile(Profile dbProfile, Profile userProfile)
	{
	}

	private Profile getProfile(User user) throws ApplicationException
	{
		return null;

	}

	@Transactional
	public Integer registerUser(User user) throws ApplicationException
	{
		return null;
	}

	public void registerUserAfterBasicRegistration(User user) throws ApplicationException
	{
	}

	public User findByUsername(String username)
	{
		return null;
	}

	public void forgotPassword(String emailId)
	{
	}

	/**
	 * Update user profile to database. If profile doesn't exist, it will be created.
	 * 
	 * @param user
	 *            The User object containing user profile.
	 * @throws ApplicationException
	 */
	public void updateUserProfile(User user) throws ApplicationException
	{
	}

	public void updateUserPassword(User bean) throws ApplicationException
	{
	}

	/**
	 * Let us verify user email id. Id and email are sent in email in encrypted format to avoid abuse.
	 * 
	 * @param id
	 *            the user id.
	 * @param email
	 *            The user email id.
	 * @return verification status. if valid true otherwise false.
	 */
	public Integer verifyEmail(String id, String email)
	{
		return null;
	}

	public void saveProfilePhoto(Integer profileId, byte[] profileImage)
	{

	}

	public byte[] getProfileImage(Integer profileId)
	{
		return null;
	}

	public boolean deleteUser(User user)
	{
		// TODO Auto-generated method stub
		return false;
	}

	public User getUser(User user1)
	{
		// TODO Auto-generated method stub
		return null;
	}

	public void updateUser(User user)
	{
		// TODO Auto-generated method stub
		
	}

	public void createUser(User user)
	{
		// TODO Auto-generated method stub
		
	}

	public User getUserByEmail(String emailId)
	{
		// TODO Auto-generated method stub
		return null;
	}

	

}
